<template>
  <div class="paper-test-settings-page">
    <PaperTestSettings 
      @start-test="onStartTest"
    />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import PaperTestSettings from './PaperTestSettings.vue';
import request from '@/api/request';
import { ElMessage } from 'element-plus';

const route = useRoute();
const router = useRouter();

const onStartTest = async (config: any) => {
  try {
    // 将参数存储到 sessionStorage，以便 PaperTestPractice 组件可以访问
    sessionStorage.setItem('paperTestParams', JSON.stringify(config));
    
    // 导航到试卷测验页面
    router.push({
      path: '/paper-test/practice',
      query: {
        paperId: config.paperId?.toString() || '',
        mode: config.mode || 'sequential',
        showAnswers: config.showAnswers?.toString() || 'false',
        paperScoreId: config.paperScoreId?.toString() || '', // 添加试卷分值ID参数
        continueProgress: config.continueProgress?.toString() || 'false' // 添加继续答题标识
      }
    });
  } catch (error) {
    console.error('开始测验失败:', error);
    ElMessage.error('开始测验失败，请稍后重试');
  }
};
</script>

<style scoped>
.paper-test-settings-page {
  width: 100%;
  min-height: calc(100vh - 64px);
  background: #f5f7fa;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
}

@media (max-width: 768px) {
  .paper-test-settings-page {
    padding: 16px;
  }
}
</style>